#include <stdlib.h>
#include <stdio.h>

void itob(int n, char s[], int b);


int main(void)
{ 		       
    char buffer[512];

    printf("Please intput the number:\n");
    int n;
    scanf("%d", &n);
    printf("Please intput the base:\n");
    int b;
    scanf("%d", &b);
    itob(n, buffer, b);

    printf("Decimal %d in base %-2d : %s\n", n, b, buffer);

    return 0;
} 		       


/*  Stores a string representation of integer n
    in s[], using a numerical base of b. Will handle
    up to base-36 before we run out of digits to use.  */

void itob(int n, char s[], int b)
{ 		       
    static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int i, sign;

    if ( b < 2 || b > 36 )
    { 		       
        fprintf(stderr, "Cannot support base %d\n", b);
        exit(EXIT_FAILURE);
    }

    if ((sign = n) < 0)
        n = -n;
    i = 0;
    do
    { 		       
        s[i++] = digits[n % b];
    }
    while ((n /= b) > 0);
    if (sign < 0)
        s[i++] = '-';
    s[i] = '\0';
    int c, j;
    for ( i = 0, j = strlen(s) - 1; i < j; i++, j--)
    { 		       
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
} 	